﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QuanLyDeTaiKHCN.Obj_class;
namespace QuanLyDeTaiKHCN.UserControls.Manager
{
    public partial class KhoiTaoDeTaiDuAn : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtMaDeTai.Text= CatalogAccess.CreateMaDeTai();
                _dbDataContext _db = new _dbDataContext();
                var list = _db.tblAcounts.Where(r=>r.ID!=1).ToList();
                ListItem items = new ListItem("---Chọn---", "-1");
                drlNguoiThuLy.Items.Add(items);
                foreach (var item in list)
                {
                    items = new ListItem(item.TenHienThi.Trim(), item.ID.ToString());
                    drlNguoiThuLy.Items.Add(items);
                }
            }
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            int loai=(rddetai.Checked==true?1:2);
            int linhvuc=(rdbtunhien.Checked==true?1:2);
            int loaihoso=(rdnhanthuyetminh.Checked==true?1:2);
            if (CatalogAccess.CreateDeTai(txtMaDeTai.Text,linhvuc, txtTenDeTaiDuAn.Text, loai, loaihoso,int.Parse(drlNguoiThuLy.SelectedValue.ToString()),txtThoiGianBanHanhDanhMuc.Text))
            {
                lblstatus.Text = "Đã tạo thành công.";
                txtMaDeTai.Text = CatalogAccess.CreateMaDeTai();
                txtTenDeTaiDuAn.Text = "";
                rddetai.Checked = true;
                rdnhanthuyetminh.Checked = true;
            }
            else
            {
                lblstatus.Text = "Không tạo được xin kiểm tra lại.";
            }
        }
    }
}